#include <iostream>
#include <unistd.h>
#include <wait.h>
#include <cstdio>
using namespace std;
int main()
{
    sleep(2);
    pid_t id = fork();
    if (id == 0)
    {
        cout << "hello world!" << endl;
        cout << "hello world!" << endl;
        cout << "hello world!" << endl;
        cout << "hello world!" << endl;
        cout << "hello world!" << endl;
        int a = 10;
        a /= 0;
        cout << "hello world!" << endl;
        cout << "hello world!" << endl;
        cout << "hello world!" << endl;
        cout << "hello world!" << endl;
    }
    // int state = 0;
    // waitpid(id, &state, 0);
    // printf("退出码：%d，核心转储：%d，退出信号：%d\n",(state>>8)&0xFF,(state>>7)&0x1,state&0x7F);
    int status = 0;
    waitpid(id, &status, 0);
    printf("signal: %d, exit code: %d, core dump: %d\n",
           (status & 0x7F), (status >> 8) & 0xFF, (status >> 7) & 0x1);
    return 0;
}
// int main()
// {
//     while(1)
//     {
//         cout<<"run"<<endl;
//         sleep(1);
//     }
//     return 0;
// }